import WebGL = Laya.WebGL;
import Handler = laya.utils.Handler;
import Loader = laya.net.Loader;
import Sprite           = Laya.Sprite;
import AccelerationInfo = Laya.AccelerationInfo;
import Accelerator      = Laya.Accelerator;
import Point            = Laya.Point;
import Browser          = Laya.Browser;
import Stage = Laya.Stage;
import Render = Laya.Render;

// 程序入口
class GameMain{
    constructor()
    {
        //初始化
        Laya.init(GameConfig.gameWidth, GameConfig.gameHeight, Laya.WebGL);
        laya.utils.Stat.show(0, 0);
        //设置适配模式
        Laya.stage.scaleMode = "showall";
        Laya.stage.alignH = "left";
        Laya.stage.alignV = "top";
        //设置横竖屏
        Laya.stage.screenMode = "horizontal";

        //管理器
        MapManager.Instance(MapManager).init();
        JsonManager.Instance(JsonManager).init();//必须写在Laya.init后面，不然无法用loader
        
        //读取引擎图集
        var resArray:Array<any>=[
            {url:"res/atlas/ui.atlas", type:Laya.Loader.ATLAS},
            //{url:"ui/back.png", type:Laya.Loader.IMAGE},//不打包的图片
        ];
        //读取图集，执行onTestLoad()
        Laya.loader.load(resArray, Laya.Handler.create(this, this.onTestLoad));
        
/*
        Laya.loader.load(resArray, Laya.Handler.create(this, null));
        //读取fgui图集
        Laya.loader.load([
        { url: "res/UIPack@atlas0.jpg", type: Loader.IMAGE },
        { url: "res/UIPack.txt", type: Loader.BUFFER }
        ], Handler.create(this, this.onLoaded));
*/
    }

    onLoaded(): void {
        //fairygui发布时，记得不要勾选压缩描述文件
        Laya.stage.addChild(fairygui.GRoot.inst.displayObject);
        fairygui.UIConfig.packageFileExtension = "txt";
        fairygui.UIPackage.addPackage("res/UIPack");
        fairygui.UIConfig.defaultFont = "Microsoft YaHei";
        //fairygui.UIConfig.verticalScrollBar = "ui://Basic/ScrollBar_VT";
        //fairygui.UIConfig.horizontalScrollBar = "ui://Basic/ScrollBar_HZ";
        //fairygui.UIConfig.popupMenu = "ui://Basic/PopupMenu";
        //fairygui.UIConfig.buttonSound = "ui://Basic/click";
        
        new MainPanel();
    }

    //测试读取play场景
    onTestLoad(): void{
        var a = new PlayTeeter();
        Laya.stage.addChild(a);
        //为啥背景颜色不变，挺奇怪

        //重力测试
        var m = new Matter_getStart(a);
    }
}
new GameMain();